<?
	/* Se asegura que el archivo es incluido por el index */
		defined( 'LOAD_MODULE_ACTION' ) or die( 'No esta permitido el acceso directo a ' . __FILE__ );
		$this->oTmpObject = new Permiso_frm( $this );

	class Permiso_frm extends Frm
	{
	function Permiso_frm( &$oModule )
		{
			$this->Frm( $oModule );
			//Crea los Objetos de los campos de edicion
				$this->aFields['ncAccion']	= new Input( "Codigo accion", "ncAccion" , '', false, true );
				$this->aFields['ncActor']	= new Input( "Codigo actor", "ncActor", '', false, true );
				$this->aFields['aAcciones']	= new InputCheck( "Acciones", "aAcciones" );
				$this->aFields['aActores']	= new InputCheck( "Actores", "aActores" );
			$this->oDatabase = openMetadataDB ( getParam('cPathModule') );
		}
	function initializeForm()
		{
				if ( $this->aFields['ncAccion']->getValue()  )
				{
					$cdAccion	= $this->oDatabase->getData("SELECT cdAccion FROM stAccion WHERE ncAccion = " . $this->aFields['ncAccion']->getValue() );
					$this->setLabel( "Pemisos para $cdAccion" );
					$this->aInput = array( 'ncAccion', 'aActores'  );
				}
				if ( $this->aFields['ncActor']->getValue()  )
				{
					$cdActor	= $this->oDatabase->getData("SELECT cdActor FROM stActor WHERE ncActor = " . $this->aFields['ncActor']->getValue() );
					$this->setLabel( "Pemisos de $cdActor" );
					$this->aInput = array( 'ncActor', 'aAcciones'  );
				}
			return true;
		}
	function initializeField( $cField , &$oField )
		{
			switch ( $cField )
			{
				case 'aActores':
					$oField->setForm( $this );
					$cSql = "SELECT Act.ncActor, Act.cdActor, Per.ncAccion
										FROM stActor as Act
										LEFT JOIN stPermiso as Per
											ON  Per.ncActor = Act.ncActor
											AND Per.ncAccion = " . $this->aFields['ncAccion']->getValue();
					$oField->setMatrix( $this->oDatabase->getMatrix( $cSql ) );
					$oField->setMultiple( true );
				break;
				case 'aAcciones':
					$oField->setForm( $this );
					$cSql = "SELECT Acc.ncAccion, Acc.cdAccion, Per.ncActor, SMo.cdSubModulo
										FROM stAccion as Acc
										LEFT JOIN stSubModulo as SMo
											ON SMo.ncSubModulo = Acc.ncSubModulo
										LEFT JOIN stPermiso as Per
											ON  Per.ncAccion = Acc.ncAccion
											AND Per.ncActor = " . $this->aFields['ncActor']->getValue();
					$oField->setMatrix( $this->oDatabase->getMatrix( $cSql ) );
					$oField->setMultiple( true );
				break;
			}
		}
	}
?>
